`
https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/
`

/**
 * @param {string} answerKey
 * @param {number} k
 * @return {number}
 */
var maxConsecutiveAnswers = function (answerKey, k) {
  const n = answerKey.length
  // [tCount, fCount]
  const cnt = [0, 0]
  let res = 0
  let left = 0, right = 0

  while (right < n) {
    const n1 = answerKey[right++] === 'T' ? 0 : 1
    cnt[n1]++

    // 只有 T 和 F 同时超过 k，才没办法同时换成相同的，缩小窗口
    while (cnt[0] > k && cnt[1] > k) {
      const n2 = answerKey[left++] === 'T' ? 0 : 1
      cnt[n2]--
    }

    // 更新答案
    res = Math.max(res, right - left)
  }

  return res
};